package kyssion.leetcode.num101_150;

import kyssion.leetcode.util.TreeNode;

public class code110_平衡二叉树 {
    public static void main(String[] args) {
        TreeNode treeNode = TreeNode.create(
                new int[]{

                }
        );
        System.out.println(new code110_平衡二叉树().isBalanced(treeNode));
    }

    boolean isTrue;

    public boolean isBalanced(TreeNode root) {
        if(root==null){
            return true;
        }
        isTrue = true;
        ans(root);
        return isTrue;
    }

    private int ans(TreeNode node) {
        if (!isTrue || node == null) {
            return 0;
        }
        int left = ans(node.left);
        int right = ans(node.right);
        isTrue = isTrue && (Math.abs(left - right) <= 1);
        return Math.max(left, right) + 1;
    }
}
